package com.lyq.controller;

import com.lyq.mapper.UsersMapper;
import com.lyq.pojo.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lyq
 * @since 2020-04-23
 */
@Controller
@RequestMapping("/users")
public class UsersContentController {
    @Autowired
    private UsersMapper usersMapper;
    @RequestMapping("/usersList")
    public String usersList(Model model){
        List<Users> usersList = usersMapper.selectList(null);
        model.addAttribute("usersList",usersList);
        return "users/usersList";
    }

    /**
     *
     * @return
     */
    @GetMapping("/toAddUsers")
    public String toAddUsers(){
        return  "users/addusers";
    }
    @PostMapping("/addUsers")
    public String addUsers(Users users) {
        usersMapper.insert(users);
        return "redirect:/usersList";

    }


}

